﻿using System.ComponentModel.Composition;
using System.Waf.Applications;
using System.Windows.Input;
using WINADM.Client.WAF.Applications.Views;
using WINADM.Data;
using System.Collections.Generic;
using System.Linq;

namespace WINADM.Client.WAF.Applications.ViewModels
{
    [Export]
    internal class MainWindowViewModel : ViewModel<IMainWindowView>
    {
        IEntityRepository _entityRepository;
        private readonly DelegateCommand exitCommand;
        IList<Application> _app;
        [ImportingConstructor]
        public MainWindowViewModel(IMainWindowView view)
            : base(view)
        {
            exitCommand = new DelegateCommand(Close);
            this._entityRepository = new WINADMEntities();
        }


        public string Title { get { return ApplicationInfo.ProductName; } }

        public ICommand ExitCommand { get { return exitCommand; } }


        public void Show()
        {
            ViewCore.Show();
        }

        private void Close()
        {
            ViewCore.Close();
        }

        public IList<Data.Application> Applications
        {
            get
            {
                var apps = from app in _entityRepository.Applications select app;
                return apps.ToList<Data.Application>();
            }
        }
    }
}
